package chixing.day11.work.w10;
// 满减策略
public class FullReductionStrategy implements PricingStrategy {
    private double threshold; // 满多少
    private double reduction; // 减多少

    public FullReductionStrategy(double threshold, double reduction) {
        this.threshold = threshold;
        this.reduction = reduction;
    }

    @Override
    public double calculate(Product product) {
        // 计算总价
        double total = product.getPrice() * product.getQuantity();
        // 计算可以减多少次
        int times = (int)(total / threshold);
        // 减去相应金额
        return total - times * reduction;
    }

    @Override
    public String toString() {
        return "满" + threshold + "减" + reduction;
    }
}

